﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Configuration;
using Windows.Foundation;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Shapes = Windows.UI.Xaml.Shapes;

namespace BoolanElement
{
    public class BooRightArrow:BooTextShapesBase
    {
        Shapes.Polygon rightArrow;
        public Shapes.Polygon RightArrow 
        {
            get
            {
                return rightArrow;
            }
            set
            {
                rightArrow = value;
            }
        }

        BooRightArrowElement rightArrowElement;
        public BooRightArrowElement RightArrowElement
        {
            get { return rightArrowElement; }
        }

        public override BooElement Element
        {
            set { rightArrowElement = (BooRightArrowElement)value; }
            get { return rightArrowElement; }
        }

        public override BooTextShapesBaseElement TextShapesBaseElement
        {
            get { return rightArrowElement; }
        }

        public override Shapes.Shape Shape
        {
            get { return rightArrow; }
        }

        public BooRightArrow(BooRightArrowElement element, SaveForRedoUndo saveForRedoUndo)
            : base(element)
        {
            this.rightArrowElement = element;
            InitOriginal();
            base.saveForRedoUndo = saveForRedoUndo;
            Focus.InitFocusEvent(this);
        }

        public BooRightArrow(BooRightArrowElement element)
            : base(element)
        {
            this.rightArrowElement = element;
            InitOriginalForThumbNails();
        }

        public override void InitShape()
        {
            rightArrow = new Shapes.Polygon();
            rightArrow.Points = BooShapesPoints.CopyPointCollection(this.rightArrowElement.Points);
            rightArrow.ManipulationMode = ManipulationModes.All;
        }

        public override void ReSizeUI(double x, double y)
        {
            if (rightArrowElement.ElementTransform.Width + x < 50 || rightArrowElement.ElementTransform.Height + y < 50)
            {
                return;
            }

            rightArrowElement.ElementTransform.Width = rightArrowElement.ElementTransform.Width + x;
            rightArrowElement.ElementTransform.Height = rightArrowElement.ElementTransform.Height + y;

            rightArrowElement.PropertyChanged("Shape");
        }

        public override void ReMargin(double x, double y)
        {
            this.Element.ElementTransform.Translate.X += x;
            this.Element.ElementTransform.Translate.Y += y;
        }


        public override void ApplySize()
        {
            rightArrowElement.ShapeWidth = rightArrowElement.ElementTransform.Width;
            rightArrowElement.ShapeHeight = rightArrowElement.ElementTransform.Height;

            //this.rightArrow.Width = rightArrowElement.ElementTransform.Width;
            //this.rightArrow.Height = rightArrowElement.ElementTransform.Height;

            FullGrid.Width = rightArrowElement.ElementTransform.Width;
            FullGrid.Height = rightArrowElement.ElementTransform.Height;

            //BooCanvas.Width = rightArrowElement.ElementTransform.Width;
            //BooCanvas.Height = rightArrowElement.ElementTransform.Height;

            CenterStack.Width = rightArrowElement.ElementTransform.Width;
            //CenterStack.MaxHeight = rightArrowElement.ElementTransform.Height;


            this.TextBox.Width = rightArrowElement.ElementTransform.Width;
            rightArrowElement.TextWidth = rightArrowElement.ElementTransform.Width;
            //this.TextBox.MaxHeight = rightArrowElement.ElementTransform.Height;
            //rightArrowElement.TextMaxHeight = rightArrowElement.ElementTransform.Height;


            Focus.FocusElls.ScopeRectangle.Width = rightArrowElement.ElementTransform.Width;
            Focus.FocusElls.ScopeRectangle.Height = rightArrowElement.ElementTransform.Height;
            Focus.SetFocuseEllipseMargin(rightArrowElement.ElementTransform.Width, rightArrowElement.ElementTransform.Height);

            Point[] pt = new Point[rightArrowElement.Points.Count];
            PointCollection pts = new PointCollection();
            rightArrowElement.Points.CopyTo(pt, 0);
            pt[0].X = rightArrowElement.ElementTransform.Width * 0.66665;
            pt[0].Y = 0;
            pt[1].X = rightArrowElement.ElementTransform.Width;
            pt[1].Y = rightArrowElement.ElementTransform.Height / 2;
            pt[2].X = rightArrowElement.ElementTransform.Width * 0.66665;
            pt[2].Y = rightArrowElement.ElementTransform.Height;
            pt[3].X = rightArrowElement.ElementTransform.Width * 0.66665;
            pt[3].Y = rightArrowElement.ElementTransform.Height * 0.75;
            pt[4].X = 0;
            pt[4].Y = rightArrowElement.ElementTransform.Height * 0.75;
            pt[5].X = 0;
            pt[5].Y = rightArrowElement.ElementTransform.Height * 0.25;
            pt[6].X = rightArrowElement.ElementTransform.Width * 0.66665;
            pt[6].Y = rightArrowElement.ElementTransform.Height * 0.25;
            pts.Add(pt[0]);
            pts.Add(pt[1]);
            pts.Add(pt[2]);
            pts.Add(pt[3]);
            pts.Add(pt[4]);
            pts.Add(pt[5]);
            pts.Add(pt[6]);
            rightArrow.Points = pts;
            rightArrowElement.Points = pts;
        }
    }
}
